package com.xy;

import com.xy.action.Action;
import com.xy.spectator.Spectator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 谢阳
 * @version 1.8.0_131
 * @date 2022/6/17 17:24
 * @description
 */
public class ObjectStructure {
    // 维护集合
    private List<Spectator> spectators = new ArrayList<>();

    /**
     * 添加
     * @param spectator
     */
    public void attach(Spectator spectator) {
        spectators.add(spectator);
    }

    /**
     * 删除
     * @param spectator
     */
    public void detach(Spectator spectator) {
        spectators.remove(spectator);
    }

    /**
     * 显示
     * @param action
     */
    public void display(Action action) {
        spectators.forEach(spectator -> spectator.accept(action));
    }
}
